package com.photoveil;

import java.util.ArrayList;
import java.util.List;

import android.util.Log;

public class ChangeLog {
	
	private static ChangeLog changeLog = new ChangeLog();
	
	public List<Change> changes = new ArrayList<Change>(50);
	public int currentChangePos = 0;
	
	public static ChangeLog getInstance() {		
		return changeLog;
	}
	
	public void addChange(Change change) {
		removeLaterChanges();
		changes.add(change);
		currentChangePos++;
		Log.i("PhotoVeil", "current: " + currentChangePos + " // size: " + changes.size());
		Log.d("PhotoVeil","Change added. oldVal: " + change.getOldValue() + ". newVal: " + change.getNewValue());
	}
	
	public Change getLastChange() {
		if (currentChangePos > 0) {
			currentChangePos--;
			return changes.get(currentChangePos);
		} else {
			return null;
		}
	}
	
	public Change getNextChange() {
		if (currentChangePos < changes.size()) {
			return changes.get(currentChangePos++);
		} else {
			return null;
		}
	}
	
	private void removeLaterChanges() {
		for(int i=changes.size(); i > currentChangePos; i--) {
			changes.remove(i-1);
		}
	}
	
	public List<Change> getChanges() {
		return changes;
	}
	
	public void clearAllChanges() {
		changes = new ArrayList<Change>(50);
		currentChangePos = 0;
	}
}
